package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MenuDao;
import com.itheima.dao.RoleDao;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = MenuService.class)
@Transactional
public class MenuServiceImpl implements MenuService {

    @Autowired
    private RoleDao roleDao;
    @Autowired
    private MenuDao menuDao;
    @Override
    public List<Menu> findMenuByRoleKeywords(List<String> keywords) {
        //通过keywords查询角色id
        List<Integer> roleIds=roleDao.findRoleIdByKeyword(keywords);
        //通过roleId查询menuId
        final List<Integer> menuIds = menuDao.findMenuIdsbyRoleIds(roleIds);
        //通过菜单Ids查询菜单
        final List<Menu> menus = menuDao.findByIds(menuIds);
        //把name属性赋值给title
        for (Menu menu : menus) {
            menu.setTitle(menu.getName());
        }
        return menus;
    }
}
